<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <form action="http://baidu.com">
        <label for="">用户名: <input type="text"></label>
        <button>按钮1</button>
        <a href="#">触发事件</a>
        <a href="#" id="reg">提交注册</a>
    </form>
    <script>

        document.querySelector('#reg').onclick=function()
        {
            document.querySelector('form').submit()  //用代码手动触发form表单的提交事件
        }
        var btn=document.querySelector("button")
        btn.onclick=function()
        {
            alert('你点了按钮1')
         
        }
        document.querySelector("a").onclick=function()
        {
            alert("点击a")
            btn.click()   //事件触发
        }


    </script>
    
</body>
</html>